from django.contrib.auth import logout
from django.http import JsonResponse
from rest_framework import viewsets
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from .models import *
from .filters import *
from .serializers import *
from utils.pagination import LargeResultsSetPagination
# Create your views here.


class SupplierViewSet(viewsets.ModelViewSet):
    serializer_class = SupplierSerializer

    queryset = Supplier.objects.all().order_by('-A001')
    filter_backends = (DjangoFilterBackend,filters.SearchFilter,filters.OrderingFilter)
    filter_class = SupplierFilter
    search_fields = ['A001','B001','B002']
    ordering_fields = ('A001','B001','B002')
    pagination_class = LargeResultsSetPagination


class ProductViewSet(viewsets.ModelViewSet):
    serializer_class = ProductSerializer

    queryset = ProductSource.objects.all().order_by('-A002')
    filter_backends = (DjangoFilterBackend,filters.SearchFilter,filters.OrderingFilter)
    filter_class = ProductFilter
    search_fields = ['F002__B001']
    ordering_fields = ('A001')
    pagination_class = LargeResultsSetPagination


class TagViewSet(viewsets.ModelViewSet):
    serializer_class = TagSerializer
    queryset = Tag.objects.all()
    pagination_class = None


class SupplierContactsViewSet(viewsets.ModelViewSet):
    serializer_class = SupplierContactsSerializer

    queryset = SupplierContacts.objects.all()
    pagination_class = LargeResultsSetPagination


class SupplierPictureViewSet(viewsets.ModelViewSet):
    queryset = SupplierPicture.objects.all()
    serializer_class = SupplierPictureSerializer
    filter_backends = (filters.SearchFilter,)
    search_fields = ['F001__B001']

